// 复杂场景 配置文件读取方式
import { readFileSync } from 'fs';
import * as yaml from 'js-yaml';
import { join } from 'path';
import * as _ from 'loadsh';

const YAML_CONFIG_FILENAME = 'config.yml';
// 读取环境变量
const YAML_CONFIG_ENV_FILENAME = `config.${process.env.NODE_MODE}.yml`;
const filePath = join(__dirname, '../config', YAML_CONFIG_FILENAME);
const fileEnv = join(__dirname, '../config', YAML_CONFIG_ENV_FILENAME);
// configModule 模块方法
export default () => {
  return _.merge(
    yaml.load(readFileSync(filePath, 'utf-8')),
    yaml.load(readFileSync(fileEnv, 'utf-8')),
  );
};
